﻿<template>
  <a-modal
    :title="title"
    width="40%"
    :visible="visible"
    :confirmLoading="loading"
    @ok="handleSubmit"
    @cancel="()=>{this.visible=false}"
  >
    <a-spin :spinning="loading">
      <a-form-model ref="form" :model="entity" :rules="rules" v-bind="layout">
        <a-form-model-item label="名称" prop="Name">
          <a-input v-model="entity.Name" autocomplete="off" placeholder="名称" />
        </a-form-model-item>
        <a-form-model-item label="简称" prop="ShortName">
          <a-input v-model="entity.ShortName" autocomplete="off" placeholder="简称" />
        </a-form-model-item>
        <a-form-model-item label="父级编号;父级编号信息" prop="ParentId">
          <a-input v-model="entity.ParentId" autocomplete="off" placeholder="父级编号;父级编号信息" />
        </a-form-model-item>
        <a-form-model-item label="层级深度" prop="LevelType">
          <a-input v-model="entity.LevelType" autocomplete="off" placeholder="层级深度" />
        </a-form-model-item>
        <a-form-model-item label="父级路径" prop="ParentPath">
          <a-input v-model="entity.ParentPath" autocomplete="off" placeholder="父级路径" />
        </a-form-model-item>
        <a-form-model-item label="省份" prop="Province">
          <a-input v-model="entity.Province" autocomplete="off" placeholder="省份" />
        </a-form-model-item>
        <a-form-model-item label="城市" prop="City">
          <a-input v-model="entity.City" autocomplete="off" placeholder="城市" />
        </a-form-model-item>
        <a-form-model-item label="城市编码" prop="CityCode">
          <a-input v-model="entity.CityCode" autocomplete="off" placeholder="城市编码" />
        </a-form-model-item>
        <a-form-model-item label="地区" prop="District">
          <a-input v-model="entity.District" autocomplete="off" placeholder="地区" />
        </a-form-model-item>
        <a-form-model-item label="省份简称" prop="ProvinceShortName">
          <a-input v-model="entity.ProvinceShortName" autocomplete="off" placeholder="省份简称" />
        </a-form-model-item>
        <a-form-model-item label="城市简称" prop="CityShortName">
          <a-input v-model="entity.CityShortName" autocomplete="off" placeholder="城市简称" />
        </a-form-model-item>
        <a-form-model-item label="地区简称" prop="DistrictShortName">
          <a-input v-model="entity.DistrictShortName" autocomplete="off" placeholder="地区简称" />
        </a-form-model-item>
        <a-form-model-item label="省份拼音" prop="ProvincePinyin">
          <a-input v-model="entity.ProvincePinyin" autocomplete="off" placeholder="省份拼音" />
        </a-form-model-item>
        <a-form-model-item label="城市拼音" prop="CityPinyin">
          <a-input v-model="entity.CityPinyin" autocomplete="off" placeholder="城市拼音" />
        </a-form-model-item>
        <a-form-model-item label="地区拼音" prop="DistrictPinyin">
          <a-input v-model="entity.DistrictPinyin" autocomplete="off" placeholder="地区拼音" />
        </a-form-model-item>
        <a-form-model-item label="位置编码;位置编码 用于地图定位区域" prop="AdCode">
          <a-input v-model="entity.AdCode" autocomplete="off" placeholder="位置编码;位置编码 用于地图定位区域" />
        </a-form-model-item>
        <a-form-model-item label="邮政编码" prop="ZipCode">
          <a-input v-model="entity.ZipCode" autocomplete="off" placeholder="邮政编码" />
        </a-form-model-item>
        <a-form-model-item label="拼音" prop="Pinyin">
          <a-input v-model="entity.Pinyin" autocomplete="off" placeholder="拼音" />
        </a-form-model-item>
        <a-form-model-item label="简拼" prop="Jianpin">
          <a-input v-model="entity.Jianpin" autocomplete="off" placeholder="简拼" />
        </a-form-model-item>
        <a-form-model-item label="首字母" prop="FirstChar">
          <a-input v-model="entity.FirstChar" autocomplete="off" placeholder="首字母" />
        </a-form-model-item>
        <a-form-model-item label="经度" prop="Longitude">
          <a-input v-model="entity.Longitude" autocomplete="off" placeholder="经度" />
        </a-form-model-item>
        <a-form-model-item label="纬度" prop="Latitude">
          <a-input v-model="entity.Latitude" autocomplete="off" placeholder="纬度" />
        </a-form-model-item>
        <a-form-model-item label="备注1" prop="Remark1">
          <a-input v-model="entity.Remark1" autocomplete="off" placeholder="备注1" />
        </a-form-model-item>
        <a-form-model-item label="备注2" prop="Remark2">
          <a-input v-model="entity.Remark2" autocomplete="off" placeholder="备注2" />
        </a-form-model-item>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
export default {
  props: {
    parentObj: Object
  },
  data () {
    return {
      layout: {
        labelCol: { span: 5 },
        wrapperCol: { span: 18 }
      },
      visible: false,
      loading: false,
      entity: {},
      rules: {},
      title: ''
    }
  },
  methods: {
    init () {
      this.visible = true
      this.entity = {}
      this.$nextTick(() => {
        this.$refs['form'].clearValidate()
      })
    },
    openForm (id, title) {
      this.init()
      this.title = title
      if (id) {
        this.loading = true
        this.$http.post('/Base_BasicData/Base_District/GetTheData', { id: id }).then(resJson => {
          this.loading = false

          this.entity = resJson.Data
        })
      }
    },
    handleSubmit () {
      this.$refs['form'].validate(valid => {
        if (!valid) {
          return
        }
        this.loading = true
        this.$http.post('/Base_BasicData/Base_District/SaveData', this.entity).then(resJson => {
          this.loading = false

          if (resJson.Success) {
            this.$message.success('操作成功!')
            this.visible = false

            this.parentObj.getDataList()
          } else {
            this.$message.error(resJson.Msg)
          }
        })
      })
    }
  }
}
</script>
